/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.biz.rest;


import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.biz.domain.ExhaustFan;
import me.zhengjie.modules.biz.service.ExhaustFanService;

import me.zhengjie.modules.biz.service.dto.ExhaustFanQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @website https://eladmin.vip
* @author Admin
* @date 2023-02-17
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "exhaust-fan管理")
@RequestMapping("/api/exhaustFan")
public class ExhaustFanController {

    private final ExhaustFanService exhaustFanService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
//    @PreAuthorize("@el.check('exhaustFan:list')")
    public void exportExhaustFan(HttpServletResponse response, ExhaustFanQueryCriteria criteria) throws IOException {
        exhaustFanService.download(exhaustFanService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询exhaust-fan")
    @ApiOperation("查询exhaust-fan")
//    @PreAuthorize("@el.check('exhaustFan:list')")
    public ResponseEntity<Object> queryExhaustFan(ExhaustFanQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(exhaustFanService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增exhaust-fan")
    @ApiOperation("新增exhaust-fan")
//    @PreAuthorize("@el.check('exhaustFan:add')")
    public ResponseEntity<Object> createExhaustFan(@Validated @RequestBody ExhaustFan resources){
        return new ResponseEntity<>(exhaustFanService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改exhaust-fan")
    @ApiOperation("修改exhaust-fan")
//    @PreAuthorize("@el.check('exhaustFan:edit')")
    public ResponseEntity<Object> updateExhaustFan(@Validated @RequestBody ExhaustFan resources){
        exhaustFanService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除exhaust-fan")
    @ApiOperation("删除exhaust-fan")
//    @PreAuthorize("@el.check('exhaustFan:del')")
    public ResponseEntity<Object> deleteExhaustFan(@RequestBody Integer[] ids) {
        exhaustFanService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @GetMapping("/3d/exhaust_fan")
    @Log("查询exhaust-fan")
    @ApiOperation("查询exhaust-fan")
    @AnonymousAccess
    public ResponseEntity<Object> queryExhaustFanFor3d(ExhaustFanQueryCriteria criteria){
        return new ResponseEntity<>(exhaustFanService.queryAll(criteria),HttpStatus.OK);
    }

    @GetMapping("/3d/exhaust_fan-floor")
    @Log("查询exhaust_fan-floor")
    @ApiOperation("查询exhaust_fan-floor")
    @AnonymousAccess
    public ResponseEntity<Object> queryExhaustFanFloorFor3d(@RequestParam Integer floor){
        return new ResponseEntity<>(exhaustFanService.queryExhaustFanFloor(floor),HttpStatus.OK);
    }

    @GetMapping("/queryDataFromPLC")
//    @Log("读取PLC数据")
    @ApiOperation("读取PLC数据")
    public ResponseEntity<Object> queryDataFromPLC(){
        exhaustFanService.queryDataFromPLC();
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @GetMapping("/3d/queryStatus")
//    @Log("读取风机状态数据")
    @ApiOperation("读取风机状态数据")
    public ResponseEntity<Object> queryStatus(){
        return new ResponseEntity<>(exhaustFanService.queryStatus(), HttpStatus.OK);
    }
}
